/*
<Copyright (C) 2011 Dru Moore>

This file is part of demorecorder.

vlc-remote is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

demorecorder is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with demorecorder.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "composition.h"
#include "utilities.h"
#include <QDebug>

Composition::Composition(QObject *parent) :
    QObject(parent)
{
    this->name = "";
    construct_composition();
}

Composition::Composition(QString name) :
    QObject(NULL)
{
    this->name = name;
    construct_composition();
}

GstElement *Composition::getComposition() {
    return this->composition;
}

QString Composition::getName() {

}

void Composition::removeSource(QString name) {
    /// TODO
}

bool Composition::addFileSource(QString name, QString location, long long start, long long duration, long long mediaStart, long long mediaDuration, int priority)
{
    GstElement *fileSrc = gst_element_factory_make("gnlfilesource", name.toLatin1());
    g_assert(fileSrc);

    if (NULL != fileSrc) {
        Utilities::setGObjectProperty(G_OBJECT(fileSrc), "location", location);
        Utilities::setGObjectProperty(G_OBJECT(fileSrc), "start", start);
        Utilities::setGObjectProperty(G_OBJECT(fileSrc), "duration", duration);
        Utilities::setGObjectProperty(G_OBJECT(fileSrc), "media-start", mediaStart);
        Utilities::setGObjectProperty(G_OBJECT(fileSrc), "media-duration", mediaDuration);
        Utilities::setGObjectProperty(G_OBJECT(fileSrc), "priority", (long)priority);

        return gst_bin_add(GST_BIN(this->composition), GST_ELEMENT(fileSrc));
    }

    return false;

}



void Composition::construct_composition()
{
   // qDebug("construct_composition");
    this->composition = gst_element_factory_make("gnlcomposition", this->name.toLatin1());
    g_assert(this->composition);
}
